<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>后台管理模板</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
	<link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
	<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
	<link rel="stylesheet" type="text/css" href="../../css/dateRange.css">
	<style type="text/css">
		.voucher-content {
			margin-top: 65px;
			margin-left: 40px;
			font-size: 14px
		}
		table.dateRangeDateTable th:first-child, table.dateRangeDateTable td:first-child {
			width: inherit;
		}
		#getVoucherTime{
			line-height: 38px;
			margin-left: 10px;
		}
	</style>
</head>
<body>
	<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
		<!--头部导航-->
		<div class="layui-header header header-demo" ></div>
		<!--左侧导航-->
		<div class="layui-side layui-bg-black" id="admin-side">
		</div>
		<!--右侧具体内容-->
		<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
			<div>
				<div class="title">编辑代金券</div>
			</div>
			<hr/>
			<div class="voucher-content">
				<form class="layui-form" action="">
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">代金券名称</label>
						<div class="layui-input-block">
							<input type="text" name="voucherName" required  lay-verify="required"  autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">代金券金额</label>
						<div class="layui-input-block">
							<input type="text" name="voucherPrice" required  lay-verify="required"  autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">所需积分</label>
						<div class="layui-input-block">
							<input type="text" name="voucherScore" required  lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item" style="margin-right: 800px">
						<label class="layui-form-label">有效日期</label>
						<div class="layui-input-block">
							<input type="text" name="vouchersDate" required  lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item" style="white-space: nowrap;">
						<label class="layui-form-label">起始领取时间</label>
						<div class="layui-input-block">
							<label id="getVoucherTime"></label>
						</div>
					</div>
					<div class="layui-form-item" style="white-space: nowrap;">
						<label class="layui-form-label">停止领取时间</label>
						<div class="layui-input-block">
							<div class="ta_date" id="div_date_demo3">
								<span class="date_title" id="date_demo3"></span>
								<a class="opt_sel" id="input_trigger_demo3" href="#">
									<i class="i_orderd"></i>
								</a>
							</div>
						</div>
					</div>
				</form>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formDemo" id="confirmedit">确认修改</button>
					</div>
				</div>
			</div>
			<!--底部导航-->
			<div class="layui-footer footer footer-demo" id="admin-footer"></div>
			<!--JS模块-->
			<script type="text/javascript" src="../../layui/layui.js"></script>
			<script src="../../js/jquery-1.12.3.min.js"></script>
			<script src="../../js/index.js"></script>
			<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
			<script type="text/javascript" src="../../js/dateRange.js"></script>
			<script>
				var data = {
					"code": 200,
					"vouchersName": "抵用券-满30立减",
					"vouchersPrice": "5",
					"vouchersFailuretime": 1500859170806,
					"vouchersState": 33187,
					"vouchersDate": 7,
					"vouchersScore": 3000,
					"vouchersType": 17604
				}
				Date.prototype.Format = function(fmt) { //author: meizz 
					var o = {
						"M+": this.getMonth() + 1, //月份 
						"d+": this.getDate(), //日 
						"h+": this.getHours(), //小时 
						"m+": this.getMinutes(), //分 
						"s+": this.getSeconds(), //秒 
						"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
						"S": this.getMilliseconds() //毫秒 
					};
					if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
					for (var k in o)
						if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
					return fmt;
				}
				var voucherId;
				layui.use('form', function() {
					var form = layui.form();
					C1 = window.location.href.split("?")[1];
					voucherId = C1.split("=")[1];
					//alert(C1);
					//alert(voucherId)
					var dateRange
					var endTime
					$.ajax({
						type: "get",
						url: "/randomdelivery/VoucherController/voucher/"+voucherId,
						data: {},
						async: true,
						dataType: "json",
						contentType: "application/json",
						success: function(data) {
							if (data.code == 200) {
						// var Startime = new Date(data.创建时间).Format("yyyy-MM-dd ") //需要传一个创建时间
						//var Startime = "2017-08-08"
						$("input[name='voucherName']").val(data.voucher.vouchersName)
						$("input[name='voucherPrice']").val(data.voucher.vouchersPrice)
						$("input[name='voucherScore']").val(data.voucher.vouchersScore)
						$("input[name='vouchersDate']").val(data.voucher.vouchersDate)
						$("#getVoucherTime").text(new Date(data.voucher.vouchersCreatetime).Format("yyyy-MM-dd"))
						var time = data.voucher.vouchersFailuretime;
						dateRange = new pickerDateRange('date_demo3', {
							calendars:1,
							isSingleDay : true,
							isTodayValid: true,
							stopToday: false,
							startDate: new Date(time).Format("yyyy-MM-dd "),
							inputTrigger: 'input_trigger_demo3',
							theme: 'ta',
							success: function(obj) {
								endTime = new Date($('#' + this.endDateId).val().replace(/-/g, "/")).Format("yyyy-MM-dd ") ;
								$("#date_demo3").text(endTime)
							}
						});
					};
				},
				Error: function() {
					alert("服务器出错");
				}
			});

					$("#confirmedit").on("click", function() {
						$.ajax({
							type: "PUT",
							url: "/randomdelivery/VoucherController/voucher",
							data: JSON.stringify({
								"vouchersId":voucherId,
								"vouchersName": $("input[name='voucherName']").val(),
								"vouchersPrice": $("input[name='voucherPrice']").val(),
								"vouchersScore": $("input[name='voucherScore']").val(),
								"vouchersDate": $("input[name='vouchersDate']").val(),
								"vouchersFailuretime": endTime,
							}),
							async: true,
							dataType: "json",
							contentType: "application/json",
							success: function(data) {
								if (data.code == 200) {
									alert("修改成功")
									window.location.href = "voucher.html"
								};
							},
							Error: function() {
								alert("服务器出错");
							}
						});
					})


				});
			</script>
		</div>
	</div>
</body>
</html>